<?php
	require_once ("../../config.inc.php");
	require_once ("../../include/mysql.inc.php");
	require_once ("../../include/article.inc.php");
	require_once ("../../include/articleType.inc.php");
	require_once ("../../include/articleMsg.inc.php");
	$articleDao = new Article();
	
	$id= mysql_escape_string($_POST["id"]);
	$articleRow = $articleDao->queryById($id);
	
	$articleTypeDao = new ArticleType();
	$typeRow = $articleTypeDao->queryById($articleRow[typeId]);//对应的类型详情
	
	$articleMsgDao = new ArticleMsg();
	$msgRows = $articleMsgDao->query($id);
	
	$dom = new DOMDocument("1.0","UTF-8");
	$article = $dom->createElement("article");
		
	$id = $dom->createElement("id", $articleRow[id]);
	$title = $dom->createElement("title", $articleRow[title]);
	$content = $dom->createElement("content", $articleRow[content]);
	$time = $dom->createElement("time", $articleRow[time]);
	$adminId = $dom->createElement("adminId", $articleRow[adminId]);
	$top = $dom->createElement("top", $articleRow[top]);
	$typeId = $dom->createElement("typeId", $articleRow[typeId]);
	$typeName = $dom->createElement("typeName", $typeRow[name]);
	
	$msgs = $dom->createElement("msgs");
	foreach ($msgRows as $msgRow) {
		$msg = $dom->createElement("msg");
		$msg->setAttribute("id",$msgRow[id]);
		
		$msgName = $dom->createElement("msgName", $msgRow[name]);
		$msgContent = $dom->createElement("msgContent", $msgRow[content]);
		$msgTime = $dom->createElement("msgTime", $msgRow[time]);
		$msgIp = $dom->createElement("msgIp", $msgRow[ip]);
		
		$msg->appendChild($msgName);
		$msg->appendChild($msgContent);
		$msg->appendChild($msgTime);
		$msg->appendChild($msgIp);
		
		$msgs->appendChild($msg);
	}
	
	$article->appendChild($id);
	$article->appendChild($title);
	$article->appendChild($content);
	$article->appendChild($time);
	$article->appendChild($adminId);
	$article->appendChild($top);
	$article->appendChild($typeId);
	$article->appendChild($typeName);
	$article->appendChild($msgs);
	
	$dom->appendChild($article);
	header("Content-type:text/xml");
	$xmlfile = $dom->saveXML();
	file_put_contents("../../xml_data/article.xml",$xmlfile);
	echo $xmlfile;
?>